﻿using System;
using System.Web.Security;
using System.Web.UI.WebControls;

namespace ProductionAnalysis.Web
{
    public partial class RolesManage_Roles : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindRoles();
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            string str1 = "此角色已存在!";
            string str2 = "添加成功!";

            if (Roles.RoleExists(TextBox1.Text.ToString().Trim()))
            {
                ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + str1 + "');</script>");
            }
            else
            {
                Roles.CreateRole(TextBox1.Text.ToString().Trim());
                ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + str2 + "');</script>");
                BindRoles();
            }
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Roles.DeleteRole(GridView1.SelectedRow.Cells[1].Text.ToString());
            BindRoles();
            GridView1.SelectedIndex = -1;
        }

        protected void BindRoles()
        {
            GridView1.DataSource = Roles.GetAllRoles();
            GridView1.DataBind();
        }
    }
}